//
//  Article.swift
//  downloadImage
//
//  Created by Galaxy on 2022/6/20.
//  详情地址管理

import Foundation
import WCDBSwift

final class ArticleModel: TableCodable {
    // ID
    var identifier: Int? = nil
    // 详情地址
    var detailUrl: String? = nil
    // 所属父id
    var fatherId: Int? = nil
    // 是否操作完毕
    var hasDone: Bool = false
    // 爬取方法
    var type: Int? = nil
    
    // 用于获取自增插入后的主键值
    var lastInsertedRowID: Int64 = 0
    // 自增
    var isAutoIncrement: Bool { true }
    enum CodingKeys: String, CodingTableKey {
        typealias Root = ArticleModel
        static let objectRelationalMapping = TableBinding(CodingKeys.self) {
            // 设置属性为自增
            BindColumnConstraint(identifier, isPrimary: true)
            BindColumnConstraint(detailUrl, isNotNull: true, defaultTo: "")
            BindColumnConstraint(fatherId, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(hasDone, isNotNull: true, defaultTo: false)
            BindColumnConstraint(type, isNotNull: true, defaultTo: 0)
        }
        case identifier
        case detailUrl
        case fatherId
        case hasDone
        case type
    }
}
